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

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

Initially, each hole has aiai 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 ii, he will put one stone in the (i+1)(i+1)-th hole, then in the (i+2)(i+2)-th, etc. If he puts a stone in the 1414-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,…,a14a1,a2,…,a14 (0≤ai≤1090≤ai≤109) — the number of stones in each hole.

It is guaranteed that for any ii (1≤i≤141≤i≤14) aiai 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 77 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 44.

PS:有n个石头洞,每个洞有奇数个或者0个石头,题目说进行一次移动,只能移动一个洞的石子进行下移。一个比较好的模拟题,只是因为要选其中最大的所以每次都要初始化,找最大值。

#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<stack>
#include<string>
const int maxn=1e5+100;
const int mod=1e9+7;
const int inf=1e9;
#define me(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
ll a[15],b[15];
ll sum()
{
       ll sum=0;
    for(int i=1;i<=14;i++)
        if(b[i]%2==0)
            sum+=b[i];
    return sum;
}
void inct()
{
    for(int i=1;i<=14;i++)
        b[i]=a[i];
}
int main()
{
    for(int i=1;i<=14;i++)
        cin>>a[i];
    ll maxn=0;
    for(int i=1;i<=14;i++)
    {  
        inct();
        int s=a[i]/14,d=a[i]%14;
        b[i]=0;
        for(int j=1;j<=14;j++)
            b[j]+=s;
        for(int j=i+1;j<=14&&d>0;d--,j++)
            b[j]++;
        for(int j=1;j<=d;j++)
            b[j]++;
        maxn=max(maxn,sum());
    }
    cout<<maxn<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41292370/article/details/81222862