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

Initially, each hole has $a_i$ 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 $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole.

It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ 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
0 1 1 0 0 0 0 0 0 7 0 0 0 0

Output
4

Input
5 1 1 1 1 0 0 0 0 0 0 0 0 0

Output
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$.

Difficulty: interview

Starter code:

Solutions:
def f(a, ind):
    if a[ind] == 0:
        return -1
    k = a[ind] // 14
    x = a[ind] % 14
    b = a[:]
    b[ind] = 0
    for j in range(14):
        b[j] += k
    for j in range(ind + 1, ind + x + 1):
        j1 = j % 14
        b[j1] += 1
    res = 0
    for j in range(14):
        if b[j] % 2 == 0:
            res += b[j]
    return res
a = list(map(int, input().split()))
ans = 0
for i in range(14):
    cur = f(a, i)
    ans = max(ans, cur)
print(ans)

def score(l):
    return sum(x*(x%2 == 0) for x in l)

res = 0
ns = list(map(int, input().split()))
for i in range(14):
    l = list(ns)
    for j in range(13):
        l[(i+1+j) % 14] += l[i]//14 + (1 if (j+1) <= l[i]%14 else 0)
    l[i] = l[i]//14
    res = max(res, score(l))

print(res)


xs = [int(x) for x in input().split()]

res = 0
for i in range(14):
    newxs = xs[:]
    newxs[i] = 0
    for j in range(14):
        newxs[j] += xs[i] // 14
    
    for j in range(xs[i] % 14):
        newxs[(i + 1 + j) % 14] += 1
    
    res = max(res, sum(val for val in newxs if val % 2 == 0))

print(res)


b = list(map(int, input().split()))
n = 14
ans = 0
for i in range(n):
    a = b.copy()
    if a[i] == 0: 
        continue
    x = a[i]
    a[i] = 0
    full = x // n
    xex = x % n
    for j in range(n):
        a[j] += full
    for j in range(xex):
        a[(i + j + 1) % n] += 1
    pot = 0
    for j in a:
        if j % 2 == 0:
            pot += j
    ans = max(ans, pot)
print(ans)




a = list(map(int, input().split()))

ans = 0
for i in range(len(a)):
    x = a[i]
    b = [j for j in a]
    b[i] = 0
    for j in range(len(a)):
        b[j] += x // 14
    
    for j in range(1, x % 14 + 1):
        b[(i + j) % 14] += 1
        
    ans_now = 0
    for j in b:
        if j % 2 == 0:
            ans_now += j
    ans = max(ans_now, ans)
print(ans)

import atexit
import io
import sys

# Buffering IO
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    

def f(a, i):
    t = a[i]
    a[i] = 0
    for j in range(14):
        a[j] += t // 14
    for j in range(t%14):
        a[(i + j + 1)%14] += 1
    
    return sum((x for x in a if x %2 == 0))
    
def main():
    a = [int(x) for x in input().split()]
    scr = 0
    for i in range(14):
        aa = a[:]
        scr= max(scr, f(aa, i))
    print(scr)

    
def __starting_point():
    main()

__starting_point()

from sys import stdin, stdout
from math import factorial
from math import log10

n = 14
challengers = list(map(int, stdin.readline().split()))
ans = 0

for i in range(n):
    if not challengers[i]:
        continue
    
    test = challengers[:]
    cnt = test[i]
    test[i] = 0
    
    for j in range(i + 1, n):
        test[j] += 1
        cnt -= 1
        
        if cnt == 0:
            break
    
    value = cnt // 14
    for j in range(n):
        test[j] += value
        cnt -= value
    
    for j in range(cnt % 14):
        test[j] += 1
        
    cur_ans = 0
    
    for z in range(n):
        if not test[z] & 1:
            cur_ans += test[z]
    
    ans = max(ans, cur_ans)

stdout.write(str(ans))

s = [int(i) for i in input().split()]
y = 0
for i in range(14):
    u = s[:]
    t = s[i]
    u[i] = 0
    ans = 0
    for c in range(14):
        u[c] += t//14
        if (c-i-1)%14 < t%14:
            u[c]+=1
        if u[c]%2 ==0:
            ans+=u[c]
    y = max(ans, y)
print(y)


arr = [int(x) for x in input().split()]
max_score = 0
for i in range(len(arr)):
    if arr[i] == 0:
        continue
    arr_copy = arr[:]
    arr_copy[i] = 0
    all_add = arr[i] // 14
    for j in range(14):
        arr_copy[j] += all_add
    for j in range(arr[i] - all_add * 14):
        arr_copy[(i + j + 1) % 14] += 1
    score = 0
    for j in arr_copy:
        if j > 0 and j % 2 == 0:
            score += j
    max_score = max(max_score, score)
print(max_score)


b = list(map(int, input().split()))
ans = 0
for i in range(14):
    a = []
    for k in range(14):
        a.append(b[k])
    count = a[i]
    a[i] = 0
    h = count % 14
    h1 = count // 14
    for j in range(i + 1, i + 1 + 14):
        if (j < i + 1 + h):
            j %= 14
            a[j] += h1 + 1
        else:
            j %= 14
            a[j] += h1
    n_ans = 0
    for k in range(14):
        if (a[k] % 2 == 0):
            n_ans += a[k]
    ans = max(ans, n_ans)
print(ans)


def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())

a = li()
ans = 0
for i in range(14):
    if a[i] == 0:
        continue
    q = a[i] // 14
    r = a[i] % 14
    b = [x + q for x in a]
    b[i] = q
    for j in range(r):
        b[(i + 1 + j) % 14] += 1
    ans = max(ans, sum(x for x in b if x % 2 == 0))
print(ans)


a = list(map(int, input().split()))
b = list()
for i in range(14):
    b.append(0)
ans = 0
ii = 0
for i in range(14):
    if a[i] > 0:
        for j in range(14):
            b[j] = a[j]
        tmp = b[i]
        cnt = b[i]//14
        tmp = b[i]%14
        b[i] = 0
        for j in range(14):
            b[j] = b[j]+cnt
        flag = (i+1)%14
        while tmp > 0:
            b[flag] = b[flag]+1
            tmp = tmp-1
            flag = (flag+1)%14
        res = 0
        for j in range(14):
            if b[j]%2 == 0:
                res = res+b[j]
        ans = max(ans, res)
print(ans)

a=list(map(int,input().split()))
m=0
for i in range(14):
    b = a[:]
    b[i] = 0
    s = a[i]
    f = s//14
    for j in range(14):b[j]+=f
    for j in range(1,s%14+1):
        b[(i+j)%14] += 1
    sc = 0
    for j in b:
        if j%2==0:sc+=j
    m = max(m,sc)
    #print(b)
print(m)


a = list(map(int, input().split()))
ans = 0
for i in range(14):
    ss = a[i]
    m = 0
    for j in range(1, 15):
        p = (i+j)% 14
        if ss == 0:
            if j != 14 and a[p] %2 == 0:
                m += a[p]
            continue
        ns = ss//14
        if ss % 14 != 0:
            ns+=1
        if j != 14 and (ns + a[p])%2 == 0:
            m += ns + a[p]
        elif j == 14 and ns %2 == 0:
            m += ns
        ss -=1
    ans = max(ans, m)
print(ans)

n = 14
a = [int(v) for v in input().split()]
assert(len(a) == n)

ans = 0

for i in range(n):
    if a[i] == 0:
        continue
    q, r = divmod(a[i], n)
    curr = 0
    for j in range(n):
        val = (a[(i + j) % n] if j != 0 else 0) + q + (1 if 1 <= j <= r else 0)
        if val % 2 == 0:
            curr += val
    ans = max(ans, curr)

print(ans)


a = list(map(int, input().split()))

result = 0

for i in range(14):
    b = a[:]
    b[i] = 0

    for j in range(i + 1, i + 15):
        b[j % 14] += a[i] // 14

    for j in range(i + 1, i + 1 + a[i] % 14):
        b[j % 14] += 1

    result = max(result, sum([x for x in b if x % 2 == 0]))

print(result)

stones = list(map(int, input().split()))
scores = []
for i in range(14):
    full = stones[i] // 14
    part = stones[i] % 14
    result = [(stones[j] if i != j else 0) + full for j in range(14)]
    for j in range(i + 1, i + part + 1):
        result[j % 14] += 1
    scores.append(sum(r for r in result if r % 2 == 0))
print(max(scores))

a = list(map(int,input().split()))
ans = 0
b = [0] * 14
for i in range(14):
    for l in range(14):
        b[l] = a[l]
    cnt = 0
    k = a[i] // 14
    k2 = a[i] % 14
    b[i] = 0
    for j in range(14):
        b[j] += k;
    for j in range(i + 1, i + k2 + 1): 
        b[j % 14] += 1;
    for j in range(14):
        if b[j] % 2 == 0:
            cnt += b[j]
        #print(b[j], end = " ")
    #print(cnt)
    
    if ans < cnt:
        ans = cnt
print(ans)

def main():
    a = [int(i) for i in input().split(' ')]
    
    ans = 0
    for i in range(14):
        if (a[i] == 0):
            continue
        b = a.copy()

        k = a[i] // 14
        r = a[i] % 14
        b[i] = 0
        for j in range(14):
            b[j] += k

        for j in range(r):
            b[(i + 1 + j) % 14] += 1

        score = 0
        for x in b:
            if x % 2 == 0:
                score += x

        ans = max(ans, score)
    print(ans)
        

main()


#!/usr/bin/env python3

ais = list(map(int, input().strip().split()))

def do(i):
	ris = list(ais)
	r = ris[i]
	ris[i] = 0
	for j in range(14):
		ris[(i + 1 + j) % 14] += (r // 14) + int((r % 14) > j)
	return sum(ri for ri in ris if (ri % 2 == 0))

m = 0
for i in range(14):
	if ais[i] > 0:
		m = max(m, do(i))

print (m)


a = list(map(int, input().split()))

def check(a):
    a = a[:]
    x = a[0]
    a[0] = 0
    for i in range(1, 14):
        a[i] += max(0, (x+14-i) // 14)
    a[0] = max(0, x // 14)
    return sum((x if x % 2 == 0 else 0 for x in a))

print(max((check(a[i:] + a[:i]) for i in range(14) if a[i] > 0)))


arr = list(map(int, input().split()))
ans = 0
for i in range(len(arr)):
    pol = arr[i] // 14
    os = arr[i] % 14
    cur = 0
    if((pol) % 2 == 0):
        cur += pol
    j = i + 1
    if(j == 14):
        j = 0
    for u in range(13):
        num = 0
        if(u < os):
            num += 1
        num += arr[j] + pol
        if(num % 2 == 0):
            cur += num
        j = j + 1
        if(j == 14):
            j = 0  
    if(cur > ans):
        #print(arr[i])
        ans = cur
print(ans)


a = list(map(int, input().split()))
mx = 0
for i in range(14):
    c = a[i]
    b = a[:]
    b[i] = 0
    res = 0
    for j in range(1, 15):
        b[(i+j)%14] += c//14
        if c%14 >= j:
            b[(i+j)%14] += 1 
        if b[(i+j)%14]%2 == 0:
            res += b[(i+j)%14]
    mx = max(res, mx)
print(mx)


rock = list(map(int, input().split()))
ma = 0
for i in range(14):
    cur_ma = 0
    cur = rock.copy()
    b = cur[i]
    cur[i] = 0
    for j in range(i + 1, 14):
        if b > 0:
            b -= 1
            cur[j] += 1
    for j in range(14):
        cur[j] += b // 14
    for j in range(b % 14):
        cur[j] += 1
    for elem in cur:
        if elem % 2 == 0:
            cur_ma += elem
    ma = max(ma, cur_ma)
print(ma)

l = list(map(int, input().split()))
ms = 0
for i in range(14):
    if l[i] > 0:
        d = l[i] // 14
        o = l[i] % 14
        nl = [l[k] for k in range(len(l))]
        nl[i] = 0
        for j in range(len(l)):
            nl[j] += d
        j = i + 1
        j %= 14
        for vbn in range(o):
            nl[j] += 1
            j += 1
            j %= 14
        s = 0
        for m in range(len(l)):
            if nl[m] % 2 == 0:
                s += nl[m]
        ms = max(ms, s)
print(ms)