a = list(map(int, input().split())) def check(x): y = x + x res = 0 for i in range(5): res += a[i] * x[i] s = sum(y[i:i+3]) if s == 0: return (False, 0) return (True, res) ans = None for i in range(1, 2**5): x = [(i>>j)&1 for j in range(5)] y = check(x) if y[0]: if ans == None or ans > y[1]: ans = y[1] print(ans)