Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.

Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.

Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has.

The second line of the input contains a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where a_{i} is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.


-----Output-----

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.


-----Examples-----
Input
5
2 4 2 3 3

Output
12

Input
3
5 5 5

Output
15

Input
6
10 10 10 1 10 10

Output
11



-----Note-----

In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.

In the second sample Vika can start to paint using any color.

In the third sample Vika should start painting using color number 5.

Difficulty: interview

Starter code:

Solutions:
am=0
x = int(input())
l = list(map(int, input().split(' ')))
m = min(l)
k = [i for i in range(x) if l[i] == m]
k.append(k[0]+x)
for i in range(len(k)-1):
    am = max(am, k[i+1]-k[i])

print(m * x + am - 1)


n = int(input())
a = list(map(int, input().split()))
minimum = min(a)
max_segment = 0
count = 0
a = a + a
for i in range(len(a)):
    if a[i] == minimum:
        max_segment = max(count, max_segment)
        count = 0
    else:
        count += 1
max_segment = max(count, max_segment)
print(minimum * n + max_segment)


import itertools
import math

n = int(input())
a = [int(x) for x in input().split()]
amin = min(a)
b = list([x for x in enumerate(a) if x[1] == amin])
l = len(b)
k = max((b[(i+1) % l][0] - b[i][0] - 1)%n for i in range(l))
print(amin*n + k)




n = int(input())
numbers = input().split(" ")
mi = 10000000007
for i in range(len(numbers)):
    mi = min(mi, int(numbers[i]))
for i in range(len(numbers)):
    numbers[i] = int(numbers[i])-mi

ret = 0
length = 0
j=0
while numbers[j] > 0:
    j+=1
for i in range(len(numbers)):
    if numbers[i] != 0:
        length+=1
    else:
        ret = max(ret, length)
        length = 0
ret = max(ret, length+j)
print(ret+n*mi)


n = int(input())
v = [int(x) for x in input().split()]
low = min(v)

res = low * n
v = [x-low for x in v]
v *= 2

start = -1
sol = 0

for i, x in enumerate(v):
    if x != 0:
        if start < 0:
            start = i
    else:
        if start >= 0:
            sol = max(sol, i-start)
            start = -1

res += sol
print(res)


n = int(input())
nums = list(map(int, input().split()))
m = min(nums)

x = [num > m for num in nums]
x = x + x

left = 0
right = 0
ans = 0
while right < 2 * n:
    if left == right:
        right += 1
    elif not x[left]:
        left += 1
    elif x[right]:
        right += 1
    else:
        ans = max(ans, right - left)
        left = right
print(n * m + ans)

n = int(input())
a = list(map(int, input().split()))
m = min(a)
b = [int(a[i] > m) for i in range(n)]
L = Max = 0
last = -1
for i in range(n):
    if b[i] == 0 and last != -1:
        Max = max(i - last, Max)
        last = -1
    elif last == -1 and b[i]:
        last = i
if last != -1:
    Max = max(n - last, Max)
if b[0] and b[-1]:
    L = 0; R = n - 1
    while b[L] and L < n - 1: L += 1
    while b[R] and L > 0: R -= 1
    L -= 1; R += 1
    Max = max(L + n - R + 1, Max)
ans = m * n + Max
print(ans)


x = int(input())
s = [int(i) for i in input().split()]
n = min(s)
count = n*x
t = 0
for i in range(x):
	s[i]-= n
s += s
m = 0
for i in s:
	if not i:
		m = max(m, t)
		t = 0
	else:
		t+=1
print(count+m)


#Vika
col=int(input())
ll=list(map(int, input().split()))
a1=col*min(ll)
m=min(ll)
s=[]
t=0
for i in ll:
    t+=1
    if i==m:
        s.append(t-1)
        t=0
s[0]+=t
print(a1+max(s))


import sys
if False:
	inp = open('B.txt', 'r')
else:
	inp = sys.stdin

n = int(inp.readline())
liters = list(map(int, inp.readline().split()))
before = 0
after = 0
low = 10**9+10
maxBetween = 0
between = 0
for i in range(n):
	if liters[i] == low:
		after = -1
		maxBetween = max(maxBetween, between)
		between = -1
	if liters[i] < low:
		before = i
		low = liters[i]
		after = -1
		between = -1
		maxBetween = 0
	after += 1
	between += 1
ans = low*n + max(maxBetween, before + after)
print(ans)


N=int(input())
x=list(map(int,input().split()))
f=min(x)
ans=N*f
curlen=0
maxlen=0
index=0
while(index<2*N):
    if (x[index%N]==f):
        maxlen=max(maxlen,curlen)
        curlen=0
    else:
        curlen+=1
    index+=1
maxlen=max(maxlen,curlen)
print(ans+maxlen)


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    mi = min(a)
    d = 0
    p = n + a.index(mi)
    for i in range(n - 1, -1, -1):
        if a[i] == mi:
            p = i
        d = max(d, p - i)
    print(mi * n + d)
    
    
    
main()

n = int(input())
a = list(map(int, input().split()))
minimum = min(a)
maximum = 0
ans = 0
ind = 0
challengers = []

for i in range(n):
    if a[i] != minimum and a[i - 1] == minimum:
        challengers.append(i)
        
while challengers:
    cnt = 0
    num = challengers.pop()
    similar = num
    while a[similar] != minimum:
        cnt += 1
        similar = (similar + 1) % n
    if cnt > maximum:
        maximum = cnt
        ind = num
    

ans = minimum * n
while a[ind] != minimum:
    ans += 1
    ind = (ind + 1) % n
print(ans)

__author__ = 'Utena'
n=int(input())
s=list(map(int,input().split()))
m=min(s)
a=[]
b=[]
for i in range(n):
    if s[i]==m:
        a.append(i)
for t in range(len(a)-1):
    b.append(a[t+1]-a[t]-1)
b.append(a[0]-a[-1]-1+n)
print(n*m+max(b))

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

# print('n', n)
# print('a', a)

minNumber = min(a)
sumA = minNumber * n

# print('sumA', sumA)

for i in range(n):
    a[i] -= minNumber

# print('a', a)

hasGoRound = False
isCounting = False
index = 0
count = 0
maxCount = 0
while True:
    # print('\ta', a[index])
    if a[index] != 0 and not isCounting:
        isCounting = True
    if a[index] != 0 and isCounting:
        count += 1
    else:
        if maxCount < count:
            maxCount = count
        if hasGoRound:
            break
        isCounting = False
        count = 0
    index += 1
    if index == n:
        index = 0
        hasGoRound = True
# print('maxCount', maxCount)
print(sumA + maxCount)

def find_right(x, data):
    answer = -1
    for i in range(len(data)):
        if data[i] == x:
            answer = i
    return answer

def find_left(x, data):
    for i in range(len(data)):
        if data[i] == x:
            return i


n = int(input())
data = list(map(int, input().split()))
min1 = min(data)
index_min_r = find_right(min1, data)
index_min_l = find_left(min1, data)
k = data.count(min1)
c = index_min_r - index_min_l - 1
help = []
for i in range(n):
    if data[i] == min1:
        help.append(i)
answer = []
for i in range(1, len(help)):
    answer.append(help[i] - help[i - 1] - 1)
answer.append(n - (help[-1] - help[0]) - 1)
print(max(answer) + n * min1)

trash = int(input());
line1 = [int(x) for x in input().split()];

low = min(line1);
lows = [];

for i in range(0, len(line1)):
    if(line1[i]==low):
        lows.append(i);

dists = [];

for i in range(1, len(lows)):
    dists.append((lows[i]-lows[i-1]) - 1);
    
dists.append( lows[0] + (len(line1)-1) - lows[-1] );

print((max(dists) + low * len(line1) ));

            



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

m = min(a)
mdist = 0

fst, l = None, None
for i in [i for i, x in enumerate(a) if x == m]:
    if fst is None:
        fst = l = i
    else:
        mdist = max(mdist, i - l - 1)
        l = i

mdist = max(mdist, fst + (n - l) - 1)
print(n*m + mdist)


n=int(input())
a=list(map(int,input().split()))
mi=min(a)
cur=0
ans=0
for i in range(3*n):
    if(a[i%n]==mi):
     cur=0
    else:
     cur+=1
    ans=max(ans,cur)
print(n*mi+ans)     
     


n = int(input())

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

m = min(colors)
longest_sub = 0
cur_sub = 0
pos = 0
break_on_min = False
while pos < n:
    if colors[pos] > m:
        cur_sub += 1
        if cur_sub > longest_sub:
            longest_sub = cur_sub
    else:
        cur_sub = 0
        if break_on_min:
            break

    pos += 1
    if pos == n and cur_sub > 0:
        pos = 0
        break_on_min = True

print(m*n + longest_sub)

n=int(input())
a=list(map(int,input().split()))
l=len(a)
m=min(a)
mi=[]
b=0
for i in range(l):
    if m==a[i]:
        mi.append(i)
if len(mi)>1:
    c=l-1-mi[-1]+mi[0]
    for i in range(len(mi)-1):
        b=mi[i+1]-mi[i]-1
        if b>c:
            c=b
    print(l*m+c)
else:
    print((m+1)*l-1)


import sys

n = int(input())
paint = list(map(int, input().split()))
low, high = min(paint), max(paint)
if low == high:
    print(n * low)
    return

count, best = 0, 0
start = paint.index(low)
pos = start
while True:
    pos += 1
    if pos == n:
        pos = 0
    if pos == start:
        break
    if paint[pos] != low:
        count += 1
        best = max(best, count)
    else:
        count = 0
print(n * low + best)


n = int(input())
l = list(map(int, input().split()))

mini = min(l)
for i in range(n): l[i] -= mini
res = mini * n
tmp = 0
maxi = 0
for i in range(2 * n):
    if l[i % n] > 0:
        tmp += 1
        if tmp > maxi: maxi = tmp
    else: tmp = 0
    
print(res + maxi)

n=int(input())
a=list(map(int,input().split()))
h=min(a)
a=a+a
pos=a.index(h)
w=0
for i in range(pos+1,2*n):
    if a[i]==h:
        w=max(w,i-pos-1)
        pos=i
print(h*n+w)

n = int(input())
col = list(map(int,input().split()))
low = min(col)
start = int()
store = list()
dist = list()
for i in range(len(col)):
    if col[i]==low:
        store.append(i+1)
        if i+1 in range(len(col)):
            start = col[i+1]
        else:
            start = col[0]
            
for j in range(len(store)):
    if j==(len(store)-1):
        dist.append(n - store[-1] + store[0])
    else:
        dist.append(store[j+1]-store[j])
        
high = max(dist)

if max(col) == min(col):
    print(max(col)*n)
elif len(store)==1:
    print(n*(low+1) -1)
else:
    print(n*(low) +( high -1))