Codeforces Round #478 (Div. 2) B. Mancala

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.

Initially, each hole has ai

stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.

Note that the counter-clockwise order means if the player takes the stones from hole i

, he will put one stone in the (i+1)-th hole, then in the (i+2)-th, etc. If he puts a stone in the 14

-th hole, the next one will be put in the first hole.

After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.

Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

Input

The only line contains 14 integers a1,a2,…,a14

(0≤ai≤109

) — the number of stones in each hole.

It is guaranteed that for any i

(1≤i≤14) ai

is either zero or odd, and there is at least one stone in the board.

Output

Output one integer, the maximum possible score after one move.

Examples

Input

Copy

0 1 1 0 0 0 0 0 0 7 0 0 0 0

Output

Copy

4

Input

Copy

5 1 1 1 1 0 0 0 0 0 0 0 0 0

Output

Copy

8

Note

In the first test case the board after the move from the hole with 7

stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to 4

.

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[20];
ll b[20];
void init()
{
    for(int i = 0; i < 14; i++)
        b[i] = a[i];
}
int main()
{
    for(int i = 0; i < 14; i++)
        scanf("%lld", &a[i]);
    ll ans = 0, sum = 0;
    for(int i = 0; i < 14; i++)
    {
        init();
        sum = 0;
        if(a[i])
        {
            b[i] = 0;
            for(int j = 0; j < 14; j++)
                b[j] += a[i] / 14;
            for(int t = 0; t < a[i] - a[i]/14 * 14; t++)
                b[(i + t + 1) % 14] ++;
            for(int k = 0; k < 14; k++)
                if(b[k] % 2 == 0)
                    sum += b[k];
            ans = max(sum, ans);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值